package org.zcode.generator.core.config;

import lombok.Data;

import java.util.Properties;

/**
 * @Description:
 * @author zhoulk
 * @date: 2019/10/28
 */
@Data
public class XmlConfig {

    public String datasourceTarget; //datasource项目路径
    public String datasourceTestTarget; //datasource Test项目路径
    public String servicePack; //datasource service包路径
    public String serviceImplPack; //datasource service实现包路径
    public String baseBeanPack; //datasource baseBeanPack 路径
    public String conditionBeanPack; //datasouce conditionBean 路径

    public String atomTargetProject; //原子层项目路径
    public String atomServicePack; //原子层api接口包路径
    public String atomControllerPack; //原子层controller包路径

    public String atomPoTarget; //原子层实体项目路径
    public String atomIPoPack; //原子层入参包路径
    public String atomOPoPack; //原子层出参包路径

    public String applicationName; //应用名
    public String applicationClazz; //应用包
    public String author;//作者名
    public boolean apiSys;//是否启用生成设计系统
    public boolean enableAtom;
    public boolean enableDatasource;
    public boolean enableTest;

    public int substring; //截取长度

    public static XmlConfig init(Properties properties) {
        XmlConfig xmlConfig = new XmlConfig();
        xmlConfig.datasourceTarget = properties.getProperty("targetProject");
        xmlConfig.datasourceTestTarget = properties.getProperty("testTargetProject");
        xmlConfig.servicePack = properties.getProperty("targetPackage");
        xmlConfig.serviceImplPack = properties.getProperty("implementationPackage");

        xmlConfig.atomTargetProject = properties.getProperty("atomTargetProject");
        xmlConfig.atomServicePack = properties.getProperty("atomServicePack");
        xmlConfig.atomControllerPack = properties.getProperty("atomControllerPack");

        xmlConfig.atomPoTarget = properties.getProperty("atomPoTarget");
        xmlConfig.atomIPoPack = properties.getProperty("atomIPoPack");
        xmlConfig.atomOPoPack = properties.getProperty("atomOPoPack");
        String application = properties.getProperty("applicationName");
        xmlConfig.applicationName = application.substring(application.lastIndexOf(".")+1);
        xmlConfig.applicationClazz = application;
        xmlConfig.author = properties.getProperty("author");
        xmlConfig.apiSys = properties.getProperty("apiSys").equals("true");
        xmlConfig.substring = Integer.valueOf(properties.getProperty("substring"));
        xmlConfig.enableAtom = properties.getProperty("enableAtom").equals("true");
        xmlConfig.enableDatasource = properties.getProperty("enableDatasource").equals("true");
        xmlConfig.enableTest = properties.getProperty("enableTest").equals("true");
        if (xmlConfig.author == null) {
            System.out.println("请配置作者名");
            System.exit(0);
            xmlConfig.author = "noAuthor";
        }
        return xmlConfig;
    }
}
